<?php
use think\Db;

/**
 * 后台通用化数据输出
 * @param int $status 业务状态码
 * @param string $message 信息提示
 * @param [] $data  数据
 * @return array
 */
function admin_json($code, $msg, $data= []) {
    $join = [
        'code' => $code,
        'msg' => $msg,
        'data' => $data,
    ];
    return json($join);
}

/**
 * 记录日志
 * @param  [type] $mid         [法师id]
 * @param  [type] $comid        [寺院id]
 * @param  [type] $description [描述]
 * @param  [type] $status      [状态]
 * @return [type]              [description]
 * @return [type] $type        0正确  -1错误日志
 */
function writelog($mid,$comid,$description,$type=0)
{
    $data['manager_id'] = $mid;
    $data['company_id'] = $comid;
    $data['description'] = $description;
    $data['status'] = $type<0 ? -1: 1;
    $data['ip'] = request()->ip();
    $data['create_time'] = time();
    Db::name('log_siyuan')->insert($data);
}

/*随机码产生*/
function getRandom($len, $chars=null){
    if (is_null($chars)){
        $chars = "abcdefghijkABCDEFGHIJKL123456789";
    }
    mt_srand(10000000*(double)microtime());
    for ($i = 0, $str = '', $lc = strlen($chars)-1; $i < $len; $i++){
        $str .= $chars[mt_rand(0, $lc)];
    }
    return $str;
}